package com.yulongtian.weekCompetition.month202301.week01;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author yulongTian
 * @create 2023-01-01 16:17
 */
public class Test02 {
    public static void main(String[] args) {
        System.out.println(getZhi(100));
    }

    public static int distinctPrimeFactors(int[] nums) {
        Set<Integer> ans = new HashSet<>();
        List<Integer> zhi = getZhi(1000);
        for (int num : nums) {
            for (Integer integer : zhi) {
                if (num % integer == 0) {
                    ans.add(integer);
                }
            }
        }
        return ans.size();
    }

    //计算2~n的质数
    public static List<Integer> getZhi(int n) {
        List<Integer> ans = new ArrayList<>();
        List<Integer> over = new ArrayList<>(n - 1);

        for (int i = 2; i <= n; i++) {
            if (!over.contains(i)) {
                ans.add(i);
                int index = 2;
                while (index * i <= n) {
                    over.add(index * i);
                    index++;
                }
            }
        }
        return ans;
    }


}
